$(function () {
    $("#login").click(function () {
        const userCode = $("#userCode").val();
        const userPassword = $("#userPassword").val();
        if (userCode === "" || userPassword === "") {
            alert("输入不能为空")
        } else {
            $.ajax(
                {
                    url: "/user/login",
                    type: "POST",
                    data: {
                        userCode: userCode,
                        userPassword: userPassword
                    },
                    error: erro,
                    success: function (data) {
                        if (data.code === 200) {
                            location.href = "/statics/jsp/user/userlist.jsp"
                        } else {
                            alert(data.msg)
                        }
                    }
                }
            )
        }
    })

    function erro() {
        alert("系统异常js")
    }

    $("#logout").click(function () {
        $.ajax(
            {
                url: "/user/logout",
                type: "POST",
                error: erro,
                success: function (data) {
                    if (data.code === 200) {
                        location.href = "../../login.jsp"
                    } else {
                        alert(data.msg)
                    }
                }
            }
        )
    })
})